# -*- coding: utf-8 -*-

# 文件名： DesModule
# 描  述：
# 作  者： besti
# 日  期： 2023/4/11
#  Have you ever seen Los Angeles at 4 a.m?
from pyDes import *
import binascii
def des_encrypt(s, KEY):
    secret_key = KEY
    iv = secret_key
    k = des(secret_key, CBC, iv, pad=None, padmode=PAD_PKCS5)
    en = k.encrypt(s, padmode=PAD_PKCS5)
    return binascii.b2a_hex(en).decode()
def des_descrypt(s, KEY):
    secret_key = KEY
    iv = secret_key
    k = des(secret_key, CBC, iv, pad=None, padmode=PAD_PKCS5)
    de = k.decrypt(binascii.a2b_hex(s), padmode=PAD_PKCS5)
    return de.decode()
if __name__ == "__main__":
    ciphertext = des_encrypt("hello, world!", "12345678")
    print("密文：",ciphertext)
    plaintext = des_descrypt(ciphertext, "12345678")
    print("解密后的明文：", plaintext)